home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / SAT / SAT Invaders sample ƒ / sPlayer.p < prev    next >
Encoding:
Text File  |  1993-09-19  |  2.4 KB  |  101 lines  |  [TEXT/PJMM]

  1. {===============================================}
  2. {================= Player sprite unit ================}
  3. {===============================================}
  4.  
  5. { Example file for Ingemars Sprite Animation Toolkit. }
  6. { © Ingemar Ragnemalm 1992 }
  7. { See doc files for legal terms for using this code. }
  8.  
  9. { This file is the first of several sprite units, units that holds the full}
  10. {description of the objects to be animated. }
  11.  
  12. unit sPlayer;
  13.  
  14. { Sprite unit. A sprite unit should include the following routines:}
  15. { Init-procedure, that initializes private bitmaps}
  16. { Setup-procedure, that sets variables other than the standard ones set by MakeSprite }
  17. { Handle-procedure, to be called once per iteration until the sprite dies }
  18. { Hittask-procedure (optional), for advanced collission handling. }
  19.  
  20. { This is the sprite unit for the player object, in this case a butterfly. }
  21.  
  22. interface
  23.  
  24.     uses
  25.         GameGlobals, SAT, SoundConst, sShot;
  26.  
  27.     var
  28.         stillRunning: boolean;
  29.  
  30.     procedure InitPlayer;
  31.     procedure SetupPlayer (player: SpritePtr);
  32.     procedure HandlePlayer (me: SpritePtr);
  33.  
  34. implementation
  35.  
  36.     const
  37.         playerspeed = 16;
  38.  
  39.     var
  40.         playerFace: FacePtr;
  41.         posh, posv: longint;
  42.  
  43.     procedure InitPlayer;
  44.         var
  45.             h: Handle;
  46.     begin
  47.         playerFace := GetFace(134);
  48.     end;
  49.  
  50.     procedure SetupPlayer (player: SpritePtr);
  51.     begin
  52.         player^.face := playerFace;
  53.         SetRect(player^.hotRect, 1, 7, 31, 32);
  54.     end;
  55.  
  56.     procedure HandlePlayer (me: SpritePtr);
  57.         var
  58.             pt: point;
  59.             shot, sp: SpritePtr;
  60.     begin
  61.         if me^.kind <> 2 then
  62.             begin
  63.                 SATSoundPlay(kraschH, 10, true);
  64.                 stillrunning := false; {Tell MoveIt that the game is over, to quit the game loop.}
  65. { Real games make an explosion first.}
  66.             end;
  67.  
  68.         SetPort(gameWind);
  69.         Getmouse(pt);
  70.  
  71.         me^.speed.h := pt.h - me^.position.h;
  72.  
  73.         if me^.speed.h < -playerspeed then
  74.             me^.position.h := me^.position.h - playerspeed
  75.         else if me^.speed.h > playerspeed then
  76.             me^.position.h := me^.position.h + playerspeed
  77.         else
  78.             me^.position.h := me^.position.h + me^.speed.h;
  79.  
  80.         if me^.position.h > offSizeH - 32 then {xsize}
  81.             begin
  82.                 me^.position.h := offSizeH - 32; { ev. xsize - 10? }
  83.             end;
  84.         if me^.position.h < 0 then
  85.             begin
  86.                 me^.position.h := 0;
  87.             end;
  88.  
  89. { Create shots }
  90.         if me^.mode > 0 then
  91.             me^.mode := pred(me^.mode);
  92.         if me^.mode = 0 then
  93.             if Button then
  94.                 begin
  95.                     sp := NewSprite(1, me^.position.h + 12, me^.position.v, @HandleShot, @SetupShot, nil);
  96.                     me^.mode := 10;
  97.                     SATSoundPlay(toffH, 1, false);
  98.                 end;
  99.     end;
  100.  
  101. end.